//
//  PersonalCell.m
//  DingDing
//
//  Created by LHL on 14/12/2.
//  Copyright (c) 2014年 com.gordon. All rights reserved.
//

#import "PersonalCell.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import <SDWebImage/UIButton+WebCache.h>
#import "UIImageView+LBBlurredImage.h"
#import "PersonalHomePage.h"
@implementation PersonalCell{
    BOOL initfunc;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)initcorner:(PETINFOMODEL *)model hasline:(BOOL)hasline{

    self.msgButton.layer.cornerRadius = self.msgButton.frame.size.height*0.5;
    if (hasline == NO) {
        self.timeline.hidden = YES;
    }else{
        self.timeline.hidden = NO;
    }
    if ([model.user_id isEqualToString:[[NSUserDefaults standardUserDefaults]objectForKey:@"user_id"]]) {
        self.msgButton.hidden = YES;
    }else{
        self.msgButton.hidden = NO;
    }
    self.ttt.layer.cornerRadius = self.ttt.frame.size.height*0.5;
    self.ttt.clipsToBounds = YES;
    self.sexImage.image = nil;
    if ([model.gender isEqualToString:@"female"]) {
        self.sexImage.image = [UIImage imageNamed:@"female_select.png"];
    }else{
        self.sexImage.image = [UIImage imageNamed:@"male_select.png"];
    }
    self.nameLabel.text = model.petname;
    [self.ttt setImageWithURL:[NSURL URLWithString:model.avatar] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType){
        if (self.block) {
            self.block();
        }
        [self.backImageView setImageToBlur:image blurRadius:3 completionBlock:^(NSError *error){
                        NSLog(@"The blurred image has been setted");
            if ([model.user_id isEqualToString:[[NSUserDefaults standardUserDefaults]objectForKey:@"user_id"]]) {
                NSData *data = [[NSUserDefaults standardUserDefaults]objectForKey:@"head_img"];
                if (data == nil) {
                    [[NSUserDefaults standardUserDefaults]setObject:UIImageJPEGRepresentation(image, 0.5) forKey:@"head_img"];
                    [[NSUserDefaults standardUserDefaults]synchronize];
                }
            }
        }];
    }];
    self.addressLabel.text = model.address;
}

-(void)getPopBlock:(popBlock)block{
    self.block = [block copy];
}

@end
